public class Solution {
    public void sortColors(int[] nums) {
        int n = nums.length;
        int ptr = 0;
        for (int i = 0; i < n; ++i) {
            if (nums[i] == 0) {
                int temp = nums[i];
                nums[i] = nums[ptr];
                nums[ptr] = temp;
                ++ptr;
            }
        }
        for (int i = ptr; i < n; ++i) {
            if (nums[i] == 1) {
                int temp = nums[i];
                nums[i] = nums[ptr];
                nums[ptr] = temp;
                ++ptr;
            }
        }
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] nums = {2, 0, 2, 1, 1, 0};
        System.out.println("Original array: ");
        for (int num : nums) {
            System.out.print(num + " ");
        }
        System.out.println();

        solution.sortColors(nums);

        System.out.println("Sorted array: ");
        for (int num : nums) {
            System.out.print(num + " ");
        }
        System.out.println();
    }
}